package com.LONE.spring6.tx.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Project ：learn_spring
 * @File ：CheckoutServiceImpl.java
 * @IDE ：IntelliJ IDEA
 * @Author ：自由如风间
 * @Date ：2025/4/5 20:07
 * @Description ：For study.
 */

@Service
public class CheckoutServiceImpl implements CheckoutService {

    @Autowired
    private BookService bookService;

    @Transactional
    @Override
    public void checkout(Integer[] bookIds, Integer userId) {
        for (Integer bookId : bookIds) {
            boolean b = bookService.buyBook(bookId, userId);
            if (!b) {
                System.out.println("买不起，别买了");
                return;
            }
        }
        System.out.println("全买下来了，好耶");
    }
}
